<template>
  <div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleTabsClick">
      <el-tab-pane label="全部" name="all" />
      <el-tab-pane label="审核通过" name="checkSuccess" />
      <el-tab-pane label="审核不通过" name="checkFailed" />
    </el-tabs>
    <el-row type="flex" class="row-bg">
      <el-col :span="8">
        <el-cascader
          clearable
          v-model="selectedArr"
          :options="city"
          @change="handleChange"
        ></el-cascader>
      </el-col>
      <el-col :span="6">
        <el-input
          :style="{ width: '250px', margin: '0 15px' }"
          placeholder="请输入内容"
          v-model="searchVal"
          clearable
        >
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </el-col>
    </el-row>
    <el-table  border  :data="tableData" stripe style="width: 100%">
      <el-table-column align="center" type="index" label="序号"></el-table-column>
      <el-table-column align="center" prop="name" label="小区名称" ><span slot-scope="scoped">{{scoped.row.name +'小区'}}</span> </el-table-column>
      <el-table-column align="center" prop="title" label="标题"> </el-table-column>
      <el-table-column align="center" prop="acreage" label="面积"><span slot-scope="scoped">{{scoped.row.acreage +'m²'}}</span> </el-table-column>
      <el-table-column align="center" prop="price" label="总价"> <span slot-scope="scoped">{{scoped.row.price +'万'}}</span></el-table-column>
      <el-table-column align="center" prop="rank" label="排序"> </el-table-column>
      <el-table-column align="center" prop="status" label="状态"><el-tag :type="scoped.row.status=='审核通过'?'success':'danger'" slot-scope="scoped">{{scoped.row.status}}</el-tag></el-table-column>
      <el-table-column align="center" label="操作" width="220">
        <template slot-scope="scoped">
          <el-button  size="mini" type="primary">审核</el-button>
          <el-button @click="editBtn(scoped.row)" size="mini" type="warning">编辑</el-button>
          <el-button @click="delData(scoped.row)" size="mini" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row>
      <el-col>
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageindex"
          :page-sizes="[10,15]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-col>
    </el-row>
    <el-dialog
      v-if="dialogVisible"
      title="编辑信息"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="diaLogClose">
      <el-form :model="auditForm" status-icon ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item  label="小区名称" prop="name">
          <el-input  v-model="auditForm.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input  v-model="auditForm.title" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="面积" prop="acreage">
          <el-input  v-model="auditForm.acreage" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item  label="总价" prop="price">
          <el-input  v-model="auditForm.price" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="排序" prop="rank">
          <el-input v-model.number="auditForm.rank"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="auditForm.status" clearable  placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="formSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import options from '../utils/cascader'
import api from '@/api/index'
export default {
  data () {
    return {
      dialogVisible: false,
      activeName: 'all',
      currentSelect: ['select1'],
      searchVal: '',
      selectedArr: [],
      city: options,
      tableData: [],
      auditForm: {
        id: '',
        name: '',
        title: '',
        acreage: '',
        price: '',
        rank: '',
        status: ''
      },
      total: 0,
      pageindex: 1,
      pagesize: 10,
      options: [{
        value: '待审核',
        label: '待审核'
      }, {
        value: '审核通过',
        label: '审核通过'
      }, {
        value: '审核不通过',
        label: '审核不通过'
      }]
    }
  },
  created () {
    this.getList()
  },
  watch: {
    activeName () {
      this.getList()
    }
  },
  methods: {
    handleTabsClick () {},
    handleChange () {},
    handleSizeChange (size) {
      this.pagesize = size
      this.getList()
    },
    handleCurrentChange (index) {
      this.pageindex = index
      this.getList()
    },
    editBtn (row) {
      console.log(row)
      this.dialogVisible = true
      for (const key in row) {
        this.auditForm[key] = row[key]
      }
    },
    async getList () {
      const { activeName, pageindex, pagesize, keyWord } = this
      const { data } = await api.getauditList({ type: activeName, pageindex, pagesize, keyWord })
      this.tableData = data.data.list
      this.total = data.data.total
    },
    async formSubmit () {
      const { auditForm } = this
      const { data } = await api.editauditList({ auditForm })
      console.log(data)
      if (data.meta.status) {
        this.$message.success(data.meta.msg)
        this.dialogVisible = false
        this.getList()
      }
    },
    async delData (row) {
      try {
        const { id } = row
        await this.$confirm('确认删除吗？')
        const { data } = await api.deleteAuditList({ id })
        if (data.meta.status) {
          this.$message.success(data.meta.msg)
          this.getList()
        } else {
          this.$message.error(data.meta.msg)
        }
      } catch (error) {

      }
    },
    async diaLogClose () {
      this.$confirm('确认关闭？')
        .then(_ => {
          this.dialogVisible = false
        })
        .catch(_ => {})
    }

  }
}
</script>

<style>

</style>
